// 50972 patriking 1032 Accepted 1288 kb 804 ms C++ 2049 B 2010-10-21 20:30:42 
#include<stdio.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

const int maxn = 10005;
typedef map<string,int>::iterator map_Itr;
map<string,int>hash;
vector<int>list[maxn];
int n;

int treedp( int root ){
	if(list[root].size() == 0){
		return 0;
	}
	vector<int>ans;
	ans.clear();
	for(int i = 0; i < list[root].size(); i++){
		ans.push_back(treedp(list[root][i]));
	}
	sort(ans.begin(),ans.end());
	int best = ans[0] + ans.size();
	for(int i = 1; i < ans.size(); i++){
		if(ans[i] + ans.size() - i > best)best = ans[i] + ans.size() - i;
	}
	return best;
}


int main()
{
	int Lcnt, x, y;
	char work1[10], work2[10];
	while(scanf("%d",&n)!=EOF)
	{
		Lcnt = 0;
		hash.clear();
		for(int i = 1; i <= n; i++)list[i].clear();
		hash["Jim"] = ++Lcnt;
		for(int i = 1; i < n; i++){
			scanf("%s%s",work1,work2);
			string w1 = string(work1,work1+strlen(work1));
			string w2 = string(work2,work2+strlen(work2));
			map_Itr itr = hash.find(w1);
			if(itr == hash.end()){
				hash[w1] = ++Lcnt;
				x = Lcnt;	
			}else{
				x = itr->second;
			}
			itr = hash.find(w2);
			if(itr == hash.end()){
				hash[w2] = ++Lcnt;
				y = Lcnt;
			}else{
				y = itr->second;
			}
			list[y].push_back(x);
		}
 		printf("%d\n",treedp(1));
	}
	return 0;
}//:/~
